package org.example.api;

import lombok.Data;

import java.io.Serializable;

@Data
public class RpcResult<T> implements Serializable {

    private static final long serialVersionUID = 1224764317931865870L;
    /**
     * 是否执行成功
     */
    private boolean isTrue = Boolean.TRUE;

    /**
     * 错误信息
     */
    private String message;

    /**
     * 结果对象
     */
    private T data;

    private RpcResult(T data){
        this.data = data;
    }

    public static <T> RpcResult<T> success(T data){
        return new RpcResult<T>(data);
    }

    public static <T> RpcResult<T> error(boolean isTrue,String message){
        return new RpcResult<T>(isTrue,message);
    }

    public static <T> RpcResult<T> error(String message){
        return new RpcResult<T>(Boolean.FALSE,message);
    }

    private RpcResult(boolean isTrue,String message){
        this.isTrue  = isTrue;
        this.message = message;
    }

    public boolean isTrue() {
        return isTrue;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }
}
